package com.LeetCode.String;

import org.junit.Test;

import java.util.HashSet;

/**
 * 无重复的最长字串
 */
public class lengthOfLongestSubstring {
    public int lengthOfLongestSubstring(String s) {
        HashSet<Character> set = new HashSet<>();
        char[] chars = s.toCharArray();
        int res = 0;
        for(int l = 0, r = 0; r < chars.length; r++){
            while(set.contains(chars[r])){
                set.remove(chars[l++]);
            }
            set.add(chars[r]);
            res = Math.max(res, r - l + 1);
        }
        return res;
    }

    @Test
    public void test(){
        String str = "pwwkew";
        System.out.println(lengthOfLongestSubstring(str));
    }
}
